package cn.com.bsoft.cloud.entity


import cn.com.bsoft.cloud.kotlin.NoArg
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonSerializer
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import java.util.*

@JsonSerialize(using = RegisterTypeSerializer::class)
@JsonDeserialize(using = RegisterTypeDeserializer::class)
enum class RegisterType(val index:Int){
    Unknown(-1),Normal(1),ZhuanJia(2),TeXu(3)
}

enum class TimeDESC(val desc:String,val defaultBegin:String,val defaultEnd:String){
    Unknown("UNKNOWN","UNKNOWN","UNKNOWN")
    ,AM("AM","08:00","11:00")
    ,PM("PM","13:30","16:30")
    ,ALL("ALL","08:00","16:30")
}


class RegisterTypeSerializer: JsonSerializer<RegisterType>() {
    override fun serialize(registerType: RegisterType?, gen: JsonGenerator?, provider: SerializerProvider?) {
        gen!!.writeNumber(registerType!!.index)
    }
}

class RegisterTypeDeserializer: JsonDeserializer<RegisterType>() {
    override fun deserialize(parser: JsonParser?, p1: DeserializationContext?): RegisterType {
        val index = parser!!.readValueAs(Int::class.java)
        return when(index){
            1 -> RegisterType.Normal
            2 -> RegisterType.ZhuanJia
            3 -> RegisterType.TeXu
            else -> RegisterType.Unknown
        }
    }

}

@NoArg
data class Arrangement(val arrangementCode: String?,
                       val hospitalCode:String,
                       val departmentCode: String,
                       val type:RegisterType,
                       val timeDesc:TimeDESC){
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    var date:Date?=null
    var startTime:String? = null
    var endTime:String? = null
    var doctorNo:String? = null
    var doctorName:String? = null
    var price:String? = null
    var total:Int? = null
    var available:Int? = null
    var departmentName: String? = null
    var outpatientLocation: String? = null
    var catalog:String? = null
    var sort:Int? = null
}

@NoArg
data class Period(val arrangementCode: String,val periodCode:String?){
    var startTime:String? = null
    var endTime:String? = null
    var total:Int? = null
    var available:Int? = null
    var date:Date? = null
}

@NoArg
data class QueryArrangementReq(val hospitalCode: String){
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    var begin:Date? = null
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    var end:Date? = null
    var departmentCode:String? = null
    var doctorNo:String? = null
}

@NoArg
data class QueryPeriodReq(val hospitalCode: String,
                          val arrangementCode: String){
    var periodCode:String? = null
}